using OrderService.Domain.Models;
using OrderService.Domain.Repositories; 
using SqlSugar;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using SharedKernel.Infrastructure.Repositories;

namespace OrderService.Infrastructure.Repositories
{
    /// <summary>
    /// 订单仓储实现
    /// </summary>
    public class OrderRepository : SqlSugarRepository<Order, Guid>, IOrderRepository
    {

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="serviceProvider">服务提供器</param>
        /// <param name="context">SqlSugar客户端</param>
        public OrderRepository(IServiceProvider serviceProvider, ISqlSugarClient context) : base(serviceProvider, context)
        { }

        /// <summary>
        /// 根据订单编号获取订单
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>订单实例</returns>
        public async Task<Order> GetByOrderNumberAsync(string orderNumber)
        {
            return await Entities.FirstAsync(o => o.OrderNumber == orderNumber);
        }
        /// <summary>
        /// 根据条件获取订单
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns>订单查询结果</returns>
        public IQueryable<Order> GetByCondition(Expression<Func<Order, bool>> condition)
        {
            return Entities.Where(condition).ToList().AsQueryable();
        }
    }
}